package com.putprize.semantic.service;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.putprize.semantic.SemanticNerer;

public class SemanticNerServlet extends HttpServlet {

	private static final long serialVersionUID = 2046745581806729069L;
	
	private SemanticNerer ner;
	
	public SemanticNerServlet(SemanticNerer n){
		ner = n;
	}
	
	@Override
	protected void doGet(HttpServletRequest rq, HttpServletResponse rp)
			throws ServletException,IOException{
		process(rq,rp);
	}
	
	@Override
	protected void doPost(HttpServletRequest rq, HttpServletResponse rp)
			throws ServletException,IOException{
		process(rq,rp);
	}
	
	void process(HttpServletRequest rq, HttpServletResponse rp)
			throws ServletException, IOException {

        rq.setCharacterEncoding("UTF-8");
		rp.setCharacterEncoding("UTF-8");
		rp.setContentType("text/html");
		
		String line = rq.getParameter("line");
		
		rq.setCharacterEncoding("UTF-8");
		PrintWriter out = rp.getWriter();
		
		String res = ner.process(line);
		
		out.println(res.trim());
	}
}


